home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Direct3D / PRTPerVertex / PRTMesh.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-28  |  4.6 KB  |  100 lines

  1. //--------------------------------------------------------------------------------------
  2. // File: PRTOptionsDlg.cpp
  3. //
  4. // Copyright (c) Microsoft Corporation. All rights reserved.
  5. //--------------------------------------------------------------------------------------
  6. #pragma once
  7.  
  8. class CPRTMesh
  9. {
  10. public:
  11.     CPRTMesh(void);
  12.     ~CPRTMesh(void);
  13.  
  14.     HRESULT OnCreateDevice( LPDIRECT3DDEVICE9 pd3dDevice );  
  15.     HRESULT OnResetDevice(); 
  16.     void    OnLostDevice(); 
  17.     void    OnDestroyDevice(); 
  18.  
  19.     void    RenderWithPRT( IDirect3DDevice9* pd3dDevice, D3DXMATRIX* pmWorldViewProj, bool bRenderWithAlbedoTexture );
  20.     void    RenderWithSHIrradEnvMap( IDirect3DDevice9* pd3dDevice, D3DXMATRIX* pmWorldViewProj, bool bRenderWithAlbedoTexture );
  21.     void    RenderWithNdotL( IDirect3DDevice9* pd3dDevice, D3DXMATRIX* pmWorldViewProj, D3DXMATRIX* pmWorldInv, bool bRenderWithAlbedoTexture, CDXUTDirectionWidget* aLightControl, int nNumLights, float fLightScale );
  22.  
  23.     HRESULT LoadMesh( IDirect3DDevice9* pd3dDevice, WCHAR* strMeshFileName );
  24.     HRESULT SetMesh( IDirect3DDevice9* pd3dDevice, ID3DXMesh* pMesh );
  25.     DWORD   GetNumVertices()    { return m_pMesh->GetNumVertices(); }
  26.     ID3DXMesh* GetMesh()        { return m_pMesh; }
  27.     D3DXMATERIAL* GetMaterials()  { return m_pMaterials; }
  28.     DWORD GetNumMaterials()  { return m_dwNumMaterials; }
  29.     bool    IsMeshLoaded()      { return (m_pMesh != NULL); }
  30.     IDirect3DTexture9* GetAlbedoTexture() { return m_pAlbedoTextures[0]; }
  31.     float   GetObjectRadius()   { return m_fObjectRadius; }
  32.     const D3DXVECTOR3& GetObjectCenter() { return m_vObjectCenter; }
  33.  
  34.     HRESULT LoadPRTBufferFromFile( WCHAR* strFile );
  35.     HRESULT LoadCompPRTBufferFromFile( WCHAR* strFile );
  36.     void    SetPRTBuffer( ID3DXPRTBuffer* pPRTBuffer, WCHAR* strFile );
  37.     void    CompressBuffer( D3DXSHCOMPRESSQUALITYTYPE Quality, UINT NumClusters, UINT NumPCA );
  38.     DWORD   GetOrder() { return m_dwOrder; }
  39.     bool    IsUncompressedBufferLoaded() { return (m_pPRTBuffer != NULL); }
  40.     bool    IsCompBufferLoaded() { return (m_pPRTCompBuffer != NULL); }
  41.     ID3DXPRTCompBuffer* GetCompBuffer() { return m_pPRTCompBuffer; }
  42.  
  43.     void    ExtractCompressedDataForPRTShader();
  44.     bool    IsShaderDataExtracted() { return (m_aClusterBases != NULL); }
  45.  
  46.     HRESULT LoadEffects( IDirect3DDevice9* pd3dDevice, const D3DCAPS9* pDeviceCaps );
  47.     bool    IsPRTEffectLoaded() { return (m_pPRTEffect != NULL); }
  48.    
  49.     void    ComputeSHIrradEnvMapConstants( float* pSHCoeffsRed, float* pSHCoeffsGreen, float* pSHCoeffsBlue );
  50.     void    ComputeShaderConstants( float* pSHCoeffsRed, float* pSHCoeffsGreen, float* pSHCoeffsBlue, DWORD dwNumCoeffsPerChannel );
  51.  
  52.     void    Cleanup()       { SAFE_RELEASE(m_pMesh); SAFE_RELEASE(m_pPRTBuffer); SAFE_RELEASE(m_pPRTCompBuffer); }
  53.  
  54. protected:
  55.     struct RELOAD_STATE
  56.     {
  57.         bool  bUseReloadState;
  58.         bool  bLoadCompressed;
  59.         WCHAR strMeshFileName[MAX_PATH];
  60.         WCHAR strPRTBufferFileName[MAX_PATH];
  61.         D3DXSHCOMPRESSQUALITYTYPE quality;
  62.         UINT dwNumClusters;
  63.         UINT dwNumPCA;
  64.     } m_ReloadState;
  65.  
  66.     ID3DXMesh*          m_pMesh;
  67.     CGrowableArray<IDirect3DTexture9*> m_pAlbedoTextures;
  68.     D3DXMATERIAL*       m_pMaterials;
  69.     ID3DXBuffer*        m_pMaterialBuffer;
  70.     DWORD               m_dwNumMaterials;
  71.     float               m_fObjectRadius;
  72.     D3DXVECTOR3         m_vObjectCenter;
  73.  
  74.     ID3DXPRTBuffer*     m_pPRTBuffer;
  75.     ID3DXPRTCompBuffer* m_pPRTCompBuffer;
  76.     ID3DXEffect*        m_pPRTEffect;       
  77.     ID3DXEffect*        m_pSHIrradEnvMapEffect;       
  78.     ID3DXEffect*        m_pNDotLEffect;       
  79.     DWORD               m_dwOrder;
  80.  
  81.     // The basis buffer is a large array of floats where 
  82.     // Call ID3DXPRTCompBuffer::ExtractBasis() to extract the basis 
  83.     // for every cluster.  The basis for a cluster is an array of
  84.     // (NumPCAVectors+1)*(NumChannels*Order^2) floats. 
  85.     // The "1+" is for the cluster mean.
  86.     float* m_aClusterBases;
  87.  
  88.     // m_aPRTConstants stores the incident radiance dotted with the transfer function.
  89.     // Each cluster has an array of floats which is the size of 
  90.     // 4+MAX_NUM_CHANNELS*NUM_PCA_VECTORS. This number comes from: there can 
  91.     // be up to 3 channels (R,G,B), and each channel can 
  92.     // have up to NUM_PCA_VECTORS of PCA vectors.  Each cluster also has 
  93.     // a mean PCA vector which is described with 4 floats (and hence the +4).
  94.     float* m_aPRTConstants;
  95.  
  96.     HRESULT AdjustMeshDecl( IDirect3DDevice9* pd3dDevice, ID3DXMesh** ppMesh );
  97.  
  98.     UINT GetOrderFromNumCoeffs( UINT dwNumCoeffs );
  99. };
  100.